from elasticsearch import Elasticsearch

from args import *

client = Elasticsearch(hosts=ELASTIC_ADDRESS, basic_auth=(ELASTIC_USERNAME, ELASTIC_PASSWORD), timeout=10000)


def mapping_and_setting(index=WRITE_INDEX_NAME):
    if client.indices.exists(index=index):
        return f"索引{WRITE_INDEX_NAME}存在，创建失败"
    result = client.indices.create(index=index, body={**mapping, **settings}, ignore=400)
    if result.get("acknowledged"):
        return f"索引{WRITE_INDEX_NAME}创建成功"
    else:
        return f"索引{WRITE_INDEX_NAME}创建失败" + result


if __name__ == '__main__':
    print(mapping_and_setting())
